﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Ket_noi_toi_VPP_bang_mo_hinh_ba_lop.Connection;

namespace Ket_noi_toi_VPP_bang_mo_hinh_ba_lop.DAL
{
    class NhomSP
    {
        private dbConnection Conn;

        public NhomSP()
        {
            Conn = new dbConnection();
        }

        public DataTable SelectAll()
        {
            return Conn.excuteSelectProcedureQuery("SelectAll_NhomSP");
        }

        public DataTable SelectID(int MaNhom)
        {
            SqlParameter[] SqlPara = new SqlParameter[1];
            SqlPara[0] = new SqlParameter("@MaNhom", SqlDbType.Int);
            SqlPara[0].Value = Convert.ToString(MaNhom);
            return Conn.excuteSelectProcedureQuery("SelectID_NhomSP", SqlPara);
        }

        public bool Insert(string TenNhom)
        {
            SqlParameter[] SqlPara=new SqlParameter[1];
            SqlPara[0] = new SqlParameter("@TenNhom",SqlDbType.NVarChar,40);
            SqlPara[0].Value = Convert.ToString(TenNhom);
            return Conn.executeInsertProcedureQuery("Insert_NhomSP",SqlPara);
        }

        public bool Update(int MaNhom, string TenNhom)
        {
            SqlParameter[] SqlPara = new SqlParameter[2];
            SqlPara[0] = new SqlParameter("@MaNhom",SqlDbType.Int);
            SqlPara[0].Value = MaNhom;
            SqlPara[1] = new SqlParameter("@TenNhom", SqlDbType.NVarChar, 40);
            SqlPara[1].Value = Convert.ToString(TenNhom);
            return Conn.executeUpdateProcedureQuery("Update_NhomSP",SqlPara);
        }

        public bool Delete(int MaNhom)
        { 
            SqlParameter[] SqlPara=new SqlParameter[1];
            SqlPara[0] = new SqlParameter("@MaNhom",SqlDbType.Int);
            SqlPara[0].Value = Convert.ToString(MaNhom);
            return Conn.executeDeleteProcedureQuery("Delete_NhomSP", SqlPara);
        }
    }
}
